---
title: 'Replication Codes for "When Voters Favour the Social Investment Welfare State," *JJPS* '
author: "Marc Brazzill, Hideko Magara, and Yuki Yanai"
date: "2020-10-26"
output:
  pdf_document:
    highlight: tango
    number_sections: no
    toc: yes
  html_document:
    highlight: tango
    theme: united
    toc: yes
    smart: no
---

```{r include = FALSE}
knitr::opts_chunk$set(warning = FALSE, 
                      echo = TRUE, 
                      message = FALSE,
                      fig.width = 7,
                      fig.height = 4)
if (knitr::is_latex_output()) {
  knitr::opts_chunk$set(dev = "cairo_pdf")
}
```

## Load Packages

```{r, message = FALSE}
if (!require(tidyverse)) {
  install.packages("tidyverse") 
  library(tidyverse)
}
if (!require(cjoint)) {
  install.packages("cjoint")
  library(cjoint)  
}

```

## Data Pre-processing

Read the data.
```{r}
conjoint_RAW <- read_csv("jjps_si_japan_brazzill-magara-yanai.csv")
```
Transform conjoint attributes into factors:
```{r}
conjoint <- conjoint_RAW %>%
  mutate(inctax = factor(inctax),
         govedu = factor(govedu),
         govfem = factor(govfem),
         govssec = factor(govssec),
         salestax = factor(salestax),
         corptax = factor(corptax),
         govccare = factor(govccare),
         govdebt = factor(govdebt))
```

Transform explanatory variables of interest into factors:
```{r}
conjoint <- conjoint %>% 
  mutate(
    # Gender
    gender = factor(gender, levels = c("female", "male")),
    
    # Social Values
    socialv2 = ifelse(socialv %in% c(1:2), 1, NA),
    socialv2 = ifelse(socialv %in% c(3:4), 2, socialv2),
    socialv2 = factor(socialv2, 
                      levels = 1:2, 
                      labels = c("libertarian", "authoritarian")),
    
    # Economic Values
    econv2 = ifelse(economicv %in% c(1:2), 1, NA),
    econv2 = ifelse(economicv %in% c(3:4), 2, econv2),
    econv2 = factor(econv2, levels = 1:2, 
                    labels = c("redistributive", "free-market")),
    
    # Income
    income = factor(income, 
                    levels = c("200less",   "200t300",   "300t400",
                               "400t500",   "500t600",   "600t700",
                               "700t800",   "800t900",   "900t1000",
                               "1000t1200", "1200t1500", "1500+")),
    income3 = ifelse(income %in% c("200less", "200t300"), 1, NA),
    income3 = ifelse(income %in% c("300t400", "400t500", "500t600"), 2, income3),
    income3 = ifelse(income %in% c("600t700", "700t800", "800t900", "900t1000", 
                                   "1000t1200", "1200t1500", "1500+"), 3, income3),
    income3 = factor(income3, 
                     levels = 1:3, 
                     labels = c("low-income", "middle-income", "high-income")),
    
    #Job Stability
    occupation = factor(occupation, 
                        levels = 1:12, 
                        labels = c("ISCO-1", "ISCO-2", "ISCO-3", "ISCO-4", 
                                   "ISCO-5", "ISCO-6", "ISCO-7", "ISCO-8", 
                                   "ISCO-9", "ISCO-10", "Student", "Unemployed")),
    jobstab = ifelse(emp_type == 6, NA, emp_type),
    jobstab = factor(jobstab, levels = 1:5, 
                     labels = c("regular",  "part-time", "haken", 
                                "contract", "self-employed")),
    jobstab2 = ifelse(jobstab == "regular", 1, NA),
    jobstab2 = ifelse(jobstab %in% c("part-time", "haken", "contract"), 2, jobstab2),
    jobstab2 = ifelse(jobstab == "self-employed", 3, jobstab2),
    jobstab2 = factor(jobstab2, levels = 1:3, 
                      labels = c("regular", "irregular", "self-employed")),
    jobstab3 = ifelse(jobstab2 == "regular", 1, NA),
    jobstab3 = ifelse(jobstab2 %in% c("irregular", "self-employed"), 2, jobstab3),
    jobstab3 = factor(jobstab3, levels = 1:2, 
                      labels = c("regular", "non-regular")),
    jobstab4 = ifelse(occupation == "Unemployed", 3, jobstab3),
    jobstab4 = factor(jobstab4, levels = 1:3,
                      labels = c("regular", "non-regular", "unemployed")),
    #Education
    educ2 = ifelse(educ %in% c("elementary", "junior-high", "high school"), 1, NA),
    educ2 = ifelse(educ %in% c("hs+", "some college"), 2, educ2),
    educ2 = ifelse(educ %in% c("bachelor", "master+"), 3, educ2),
    educ2 = factor(educ2, levels = 1:3, labels = c("no college", "some college",
                                                   "bachelor+")))
```

Create a data set including only respondents who answered the conjoint experiment.
```{r}
conjoint_comp <- filter(conjoint, !is.na(selected))
conjoint2 <- conjoint_comp %>% 
  rename(`IncomeTax` = inctax,
         `Education` = govedu,
         `WomenEmployment` = govfem,
         `SocialSecurity` = govssec,
         `SalesTax` = salestax,
         `CorporateTax` = corptax,
         `Childcare` = govccare,
         `GovtDebt` = govdebt)
```

### Prepare the Conjoint Analysis

Conjoint attributes
```{r}
conjoint_attr <- c("IncomeTax", "Education", "WomenEmployment", "SocialSecurity",
                   "SalesTax", "CorporateTax", "Childcare", "GovtDebt")
```


Create the design object
```{r}
attr_list2 <- list()
for (A in conjoint_attr) {
  attr_list2[[A]] <- unique(pull(conjoint2, A))
}
si_design2 <- makeDesign(type = "constraints", attribute.levels = attr_list2)
```

Set the baseline values for the attributes.
```{r}
base_list2 <- list()
for (A in conjoint_attr[1:7]) {
  base_list2[[A]] <- "sq"
}
base_list2[["GovtDebt"]] <- "noIncrease"
```


## Conjoint Analysis

### The Base Model

```{r}
cj_base2 <- amce(selected ~ `SocialSecurity` + `Education` + `WomenEmployment` + `Childcare` + 
                   `IncomeTax` + `SalesTax` + `CorporateTax` + `GovtDebt`,
                 data = conjoint2,
                 design = si_design2,
                 respondent.id = "ID",
                 baselines = base_list2)
```

Figure 1
```{r}
ccare <- as_tibble(t(cj_base2[["estimates"]]$Childcare)) %>% 
  rename(se = "Std. Error") %>% 
  mutate(policy_pos = c("Decrease", "Increase"),
         policy = "Childcare",
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  select(3, 1:2, 4:6) %>% 
  add_row(policy_pos = "Childcare:")
edu <- as_tibble(t(cj_base2[["estimates"]]$Education)) %>% 
  rename(se = "Std. Error") %>% 
  mutate(policy_pos = c(" Decrease", " Increase"),
         policy = "Education",
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  select(3, 1:2, 4:6) %>% 
  add_row(policy_pos = "Education:")
women <- as_tibble(t(cj_base2[["estimates"]]$WomenEmployment)) %>% 
  rename(se = "Std. Error") %>% 
  mutate(policy_pos = c("  Decrease", "  Increase"),
         policy = "Promoting Women's Employment",
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  select(3, 1:2, 4:6) %>% 
  add_row(policy_pos = "Women's Employment:")

basic_data <- tibble() 
basic_data <- bind_rows(basic_data, ccare, edu, women) %>% 
  mutate(policy_pos = factor(policy_pos, 
                             levels = c("  Decrease", "  Increase", "Women's Employment:",
                                        " Decrease", " Increase", "Education:",
                                        "Decrease", "Increase", "Childcare:")))

basic_plot <- 
  ggplot(data = basic_data,
         mapping = aes(y = policy_pos,
                       x = AMCE,
                       colour = policy)) +
  geom_vline(aes(xintercept = 0)) +
  geom_pointrange(mapping = aes(xmin = lower, 
                                xmax = upper)) +
  xlim(-0.1, 0.1) +
  scale_y_discrete(labels = c("  Decrease", "  Increase", 
                              expression(bold("Women's Employment:")),
                              " Decrease", " Increase", 
                              expression(bold("Education:")),
                              "Decrease", "Increase", 
                              expression(bold("Childcare:")))) + 
  labs(x = "Change in support for the candidate") +
  theme_minimal() +
  theme(legend.position = "none",
        axis.title.y = element_blank())

plot(basic_plot)
```

```{r, eval = FALSE}
# This block works only on macOS with Quartz (XQuartz)
quartz(file = "conjoint_basic.pdf", type = "pdf", family = "sans",
       width = 7, height = 2.5)
print(basic_plot)
dev.off()
```


### Respondent Varying Models

*Income*
```{r}
conjoint_income2 <- filter(conjoint2, !is.na(income3))
cj_income2 <- amce(selected ~ SocialSecurity:income3 + Education:income3 + 
                     WomenEmployment:income3 + Childcare:income3 + 
                     IncomeTax:income3 + SalesTax:income3 + 
                     CorporateTax:income3 + GovtDebt:income3,
                   data = conjoint_income2,
                   design = si_design2,
                   respondent.id = "ID",
                   respondent.varying = "income3",
                   baselines = base_list2)
```

```{r}
low <- summary(cj_income2)[["income31amce"]]
middle <- summary(cj_income2)[["income32amce"]]
high <- summary(cj_income2)[["income33amce"]]

low <- low %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(income = "Low Income")

middle <- middle %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(income = "Middle Income")

high <- high %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(income = "High Income")

income_data <- tibble()
income_data <- bind_rows(income_data, low, middle, high) %>% 
  mutate(policy_pos = factor(policy_pos, 
                             levels = c("  Decrease", "  Increase", "Women's Employment:",
                                        " Decrease", " Increase", "Education:",
                                        "Decrease", "Increase", "Childcare:")),
         income = factor(income,
                         levels = c("Low Income", "Middle Income", "High Income")))
```

Figure 2
```{r}
income_plot <- 
  ggplot(data = income_data,
         mapping = aes(y = policy_pos,
                       x = AMCE,
                       colour = policy)) +
  geom_vline(aes(xintercept = 0)) +
  geom_pointrange(mapping = aes(xmin = lower, 
                                xmax = upper)) +
  scale_y_discrete(labels = c("  Decrease", "  Increase", 
                              expression(bold("Women's Employment:")),
                              " Decrease", " Increase",
                              expression(bold("Education:")),
                              "Decrease", "Increase", 
                              expression(bold("Childcare:")))) + 
  scale_x_continuous(breaks = c(-0.1, 0, 0.1)) +
  labs(x = "Change in support for the candidate") +
  facet_grid(cols = vars(income)) +
  theme_minimal() +
  theme(legend.position = "none",
        axis.title.y = element_blank(),
        strip.text.x = element_text(face = "bold"),
        panel.border = element_rect(colour = "black", size = 0.3, fill = NA))

plot(income_plot)
```


```{r, eval = FALSE}
# This block works only on macOS with Quartz (XQuartz)
quartz(file = "conjoint_income.pdf", type = "pdf", family = "sans",
       width = 7, height = 2.5)
print(income_plot)
dev.off()
```


*Gender*
```{r}
cj_gender2 <- amce(selected ~ SocialSecurity:gender + Education:gender + WomenEmployment:gender + 
                     Childcare:gender + IncomeTax:gender + SalesTax:gender + 
                     CorporateTax:gender + GovtDebt:gender,
                   data = conjoint2,
                   design = si_design2,
                   respondent.id = "ID",
                   respondent.varying = "gender",
                   baselines = base_list2)
```

```{r}
female <- summary(cj_gender2)[["gender1amce"]]
male <- summary(cj_gender2)[["gender2amce"]]

female <- female %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(gender = "Female")

male <- male %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(gender = "Male")

gender_data <- tibble()
gender_data <- bind_rows(gender_data, female, male) %>% 
  mutate(policy_pos = factor(policy_pos, 
                             levels = c("  Decrease", "  Increase", "Women's Employment:",
                                        " Decrease", " Increase", "Education:",
                                        "Decrease", "Increase", "Childcare:")))
```

Figure 3
```{r}
gender_plot <- 
  ggplot(data = gender_data,
         mapping = aes(y = policy_pos,
                       x = AMCE,
                       colour = policy)) +
  geom_vline(aes(xintercept = 0)) +
  geom_pointrange(mapping = aes(xmin = lower, 
                                xmax = upper)) +
  xlim(-0.12, 0.12) +
  scale_y_discrete(labels = c("  Decrease", "  Increase", 
                              expression(bold("Women's Employment:")),
                              " Decrease", " Increase", 
                              expression(bold("Education:")),
                              "Decrease", "Increase", 
                              expression(bold("Childcare:")))) + 
  labs(x = "Change in support for the candidate") +
  facet_grid(cols = vars(gender)) +
  theme_minimal() +
  theme(legend.position = "none",
        axis.title.y = element_blank(),
        strip.text.x = element_text(face = "bold"),
        panel.border = element_rect(colour = "black", size = 0.3, fill = NA))

plot(gender_plot)
```

```{r, eval = FALSE}
# This block works only on macOS with Quartz (XQuartz)
quartz(file = "conjoint_gender.pdf", type = "pdf", family = "sans",
       width = 7, height = 2.5)
print(gender_plot)
dev.off()
```

*Social Values*
```{r}
conjoint_socialv2 <- filter(conjoint2, !is.na(socialv2))
cj_socialv2 <- amce(selected ~ SocialSecurity:socialv2 + Education:socialv2 +
                      WomenEmployment:socialv2 + 
                      Childcare:socialv2 + IncomeTax:socialv2 + SalesTax:socialv2 + 
                      CorporateTax:socialv2 + GovtDebt:socialv2,
                    data = conjoint_socialv2,
                    design = si_design2,
                    respondent.id = "ID",
                    respondent.varying = "socialv2",
                    baselines = base_list2)
```

```{r}
lib <- summary(cj_socialv2)[["socialv21amce"]]
auth <- summary(cj_socialv2)[["socialv22amce"]]

lib <- lib %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(socialv = "Libertarian")

auth <- auth %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c(" Decrease", " Increase",
                        "  Decrease", "  Increase",
                        "Decrease", "Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(socialv = "Authoritarian")

socialv_data <- tibble()
socialv_data <- bind_rows(socialv_data, lib, auth) %>% 
  mutate(policy_pos = factor(policy_pos, 
                             levels = c("  Decrease", "  Increase", "Women's Employment:",
                                        " Decrease", " Increase", "Education:",
                                        "Decrease", "Increase", "Childcare:")))
```

Figure 5 (in Appendix)
```{r}
socialv_plot <- 
  ggplot(data = socialv_data,
         mapping = aes(y = policy_pos,
                       x = AMCE,
                       colour = policy)) +
  geom_vline(aes(xintercept = 0)) +
  geom_pointrange(mapping = aes(xmin = lower, 
                                xmax = upper)) +
  scale_y_discrete(labels = c("  Decrease", "  Increase", 
                              expression(bold("Women's Employment:")),
                              " Decrease", " Increase", 
                              expression(bold("Education:")),
                              "Decrease", "Increase", 
                              expression(bold("Childcare:")))) + 
  labs(x = "Change in support for the candidate") +
  facet_grid(cols = vars(socialv)) +
  theme_minimal() +
  theme(legend.position = "none",
        axis.title.y = element_blank(),
        strip.text.x = element_text(face = "bold"),
        panel.border = element_rect(colour = "black", size = 0.3, fill = NA))

plot(socialv_plot)
```

```{r, eval = FALSE}
# This block works only on macOS with Quartz (XQuartz)
quartz(file = "conjoint_socialv.pdf", type = "pdf", family = "sans",
       width = 7, height = 2.5)
print(socialv_plot)
dev.off()
```



**Subsetting based on Social Security Spending**

Create a new baselines list excluding SocialSecurity
```{r}
base_list_ssec <- list()
for (A in conjoint_attr[1:3]) {
  base_list_ssec[[A]] <- "sq"
}
for (A in conjoint_attr[5:7]) {
  base_list_ssec[[A]] <- "sq"
}
base_list_ssec[["GovtDebt"]] <- "noIncrease"
```

Subset the data so only candidates who will decrease social security are selected
```{r}
conjoint_ss_dec <- conjoint2 %>% 
  filter(SocialSecurity  == "decrease") 
```

Run the conjoint analysis
```{r}
cj_ss_dec <- amce(selected ~ Education + WomenEmployment + Childcare + 
                    IncomeTax + SalesTax + CorporateTax + GovtDebt,
                  data = conjoint_ss_dec,
                  design = si_design2,
                  respondent.id = "ID",
                  baselines = base_list_ssec)
```

Subset the data so only candidates who will maitain the current level of social security are selected
```{r}
conjoint_ss_sq <- conjoint2 %>% 
  filter(SocialSecurity  == "sq") 
```

Run the conjoint analysis
```{r}
cj_ss_sq <- amce(selected ~ Education + WomenEmployment + Childcare + 
                   IncomeTax + SalesTax + CorporateTax + GovtDebt,
                 data = conjoint_ss_sq,
                 design = si_design2,
                 respondent.id = "ID",
                 baselines = base_list_ssec)
```

Subset the data so only candidates who will increase social security are selected
```{r}
conjoint_ss_inc <- conjoint2 %>% 
  filter(SocialSecurity == "increase") 
```

Run the conjoint analysis
```{r}
cj_ss_inc <- amce(selected ~ Education + WomenEmployment + Childcare + 
                    IncomeTax + SalesTax + CorporateTax + GovtDebt,
                  data = conjoint_ss_inc,
                  design = si_design2,
                  respondent.id = "ID",
                  baselines = base_list_ssec)
```

```{r}
ssdec <- summary(cj_ss_dec)[["amce"]]
sssq <- summary(cj_ss_sq)[["amce"]]
ssinc <- summary(cj_ss_inc)[["amce"]]

ssdec <- ssdec %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c("Decrease", "Increase",
                        " Decrease", " Increase",
                        "  Decrease", "  Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(socsec = "Social Security Decrease")

sssq <- sssq %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c("Decrease", "Increase",
                        " Decrease", " Increase",
                        "  Decrease", "  Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(socsec = "Social Security Unchanged")

ssinc <- ssinc %>% 
  filter(Attribute %in% c("Education", "Childcare", "WomenEmployment")) %>% 
  select(1:4) %>% 
  rename(AMCE = Estimate,
         se = "Std. Err",
         policy = Attribute) %>% 
  mutate(policy_pos = c("Decrease", "Increase",
                        " Decrease", " Increase",
                        "  Decrease", "  Increase"),
         lower = AMCE - (1.96 * se),
         upper = AMCE + (1.96 * se)) %>% 
  add_row(policy_pos = "Childcare:") %>% 
  add_row(policy_pos = "Education:") %>%
  add_row(policy_pos = "Women's Employment:") %>% 
  mutate(socsec = "Social Security Increase")

socsec_data <- tibble()
socsec_data <- bind_rows(socsec_data, ssdec, sssq, ssinc) %>% 
  mutate(policy_pos = factor(policy_pos, 
                             levels = c("  Decrease", "  Increase", "Women's Employment:",
                                        " Decrease", " Increase", "Education:",
                                        "Decrease", "Increase", "Childcare:")),
         socsec = factor(socsec,
                         levels = c("Social Security Decrease", "Social Security Unchanged", 
                                    "Social Security Increase")))
```


Figure 4
```{r}
socsec_plot <- 
  ggplot(data = socsec_data,
         mapping = aes(y = policy_pos,
                       x = AMCE,
                       colour = policy)) +
  geom_vline(aes(xintercept = 0)) +
  geom_pointrange(mapping = aes(xmin = lower, 
                                xmax = upper)) +
  scale_y_discrete(labels = c("  Decrease", "  Increase", 
                              expression(bold("Women's Employment:")),
                              " Decrease", " Increase", 
                              expression(bold("Education:")),
                              "Decrease", "Increase", 
                              expression(bold("Childcare:")))) + 
  scale_x_continuous(breaks = c(-0.1, 0, 0.1),
                     limits = c(-0.142, 0.133)) +
  labs(x = "Change in support for the candidate") +
  facet_grid(cols = vars(socsec)) +
  theme_minimal() +
  theme(legend.position = "none",
        axis.title.y = element_blank(),
        strip.text.x = element_text(face = "bold"),
        panel.border = element_rect(colour = "black", size = 0.3, fill = NA))

plot(socsec_plot)
```

```{r, eval = FALSE}
# This block works only on macOS with Quartz (XQuartz)
quartz(file = "conjoint_socsec.pdf", type = "pdf", family = "sans",
       width = 7, height = 2.5)
print(socsec_plot)
dev.off()
```
